#include "waiting.h"
#include <QDebug>

Waiting::Waiting(QWidget *parent)
    : QDialog(parent),
      m_movie(nullptr)
{   
    this->setFixedSize(300, 300);

    //设置透明度
    this->setStyleSheet("border-style:solid;;border-radius:20px;background-color: transparent;");
    this->setWindowFlags(Qt::FramelessWindowHint | Qt::Dialog);
    this->setAttribute(Qt::WA_TranslucentBackground);
    this->setWindowModality(Qt::WindowModal);

    m_background = new QFrame(this);
    m_background->setStyleSheet("background-color: rgba(3, 48, 106, 1);");
    m_background->setGeometry(75, 75, 150, 150);

    m_label = new QLabel(m_background);
    m_label->setGeometry(0, 0, 150, 150);

    m_movie = new QMovie(":/images/images/Search.gif");
    m_movie->setSpeed(60);

    // 添加阴影
    m_pEffect = new QGraphicsDropShadowEffect(m_background);
    m_pEffect->setOffset(0, 0);
    m_pEffect->setColor(QColor(QStringLiteral("black")));
    m_pEffect->setBlurRadius(30);
    m_background->setGraphicsEffect(m_pEffect);

    /*
    // 此处可以设置成无背景框的等待效果
    this->setFixedSize(150, 150);
    this->setStyleSheet("border-style:solid;border-radius:20px;background-color: transparent;");
    setWindowFlags(Qt::FramelessWindowHint | Qt::Dialog);
    this->setAttribute(Qt::WA_TranslucentBackground);
    this->setWindowModality(Qt::WindowModal);

    m_label = new QLabel(this);
    m_label->setGeometry(0, 0, 150, 150);

    m_movie = new QMovie(":/images/images/Search.gif");
    m_movie->setSpeed(80);
    */
}

Waiting::~Waiting()
{
    m_movie->stop();
    delete m_movie;
}

void Waiting::prepare()
{
    m_movie->start();
    m_label->setScaledContents(true);
    m_label->setMovie(m_movie);
}

